$(document).ready (function() {
  $('.talk').scrollTop( $('.talk ul').height());
  
  $('button').click(function(){
     var news=$('input[name=new]').val();
     var uid=$('input[name=uid]').val();
     var name=$('input[name=name]').val();   
       jQuery.ajax(
          { url: "plugin.php?id=Annual:verify",
            data:{
            	  action:"talk",
            	  news:news,
            	  uid:uid,
            	  name:name,
            	 },
            dataType:"json",
               type:"POST",
               async:false,
               success:function(data) {
               	//console.log(data);
               if(data == "1"){
                 $('input[name=new]').val("").focus();
               }
             }
        });
   });  	

  //获取留言列表
  function talkList(){  
  	var nid= $("ul li:last-child").val();
      $.ajax(
          {  
          	 type:"POST",
          	 url: "plugin.php?id=Annual:verify",
          	   data:{
          	      action:'newlist',
          	   	  nid:nid,
          	   },
               dataType:"json",
               async:false,
               success:function(data) {
                newAdd(data);
             }
        });
   }
  
 function newAdd(data){
 	console.log(data.length);
   for (var i = 0; i <data.length; i++) {
    var str ="<li value="+data[i]['id']+">";
       str+="<img src='uc_server/avatar.php?uid="+data[i]['uid']+"&size=small'>";
       str+="<div><h3>"+data[i]['name']+"</h3></div>";
       str+="<p>"+data[i]['new']+"</p>"
       str+="</li>"
        $('ul').append(str);
   }
  $('.talk').scrollTop( $('.talk ul').height());   
  }  
 //定时刷新页面数据
 setInterval(talkList,3000);
});


